package com.kejizhentan.controller;

import com.github.pagehelper.PageInfo;
import com.kejizhentan.service.IOrdersService;
import com.kejizhetan.bean.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @Auther: kejizhentan
 * @Date 2022/3/5 14:19
 * @Description: 订单操作的相关接口
 */
@RequestMapping("/orders")
@Controller
public class OrdersController {
    @Autowired
    private IOrdersService ordersService;
    /**
     * @descrition：  查询所有订单
     * @param:
     * @return:
     * @auther: kejizhentan
     * @date: 2022/3/5 14:21
     */
    @RequestMapping("/findAll.do")
    public ModelAndView findAll(@RequestParam(name="page",required = true,defaultValue = "1") int page,@RequestParam(name="size",required = true,defaultValue = "4") int size) throws Exception {
        List<Orders> list = ordersService.findAll(page,size);
        PageInfo pageInfo = new PageInfo(list);
        ModelAndView mv = new ModelAndView();
        mv.addObject("pageInfo",pageInfo);
        mv.setViewName("orders-list");
        return mv;
    }

    @RequestMapping("/findById.do")
    public ModelAndView findById(@RequestParam(name = "id",required = true) String OrderId) throws Exception {
        ModelAndView mv = new ModelAndView();
        Orders orders = ordersService.findById(OrderId);
        mv.addObject("orders",orders);
        mv.setViewName("orders-show");
        return mv;
    }
}
